<template>
  <view>
    <!-- search -->
    <view class="search-box">
      <my-search @click='gotoSearch'></my-search>
    </view>
    
    <!-- 轮播图 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular class="swiperBox">
      <swiper-item v-for="(item,i) in swiperList" :key='i'>
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
          <image :src="item.image_src" mode="widthFix"></image>
        </navigator>
      </swiper-item>
    </swiper>
    
    <!-- nav导航栏 -->
    <view class="nav-list">
      <view @click="onNavClickHandle(item)" class="nav-item" v-for="(item,i) in navList" :key='i'>
        <image :src="item.image_src" mode="widthFix"></image>
      </view>
    </view>
    
    <!-- 商品楼层 -->
    <view class="floor-list">
      <view class="floor-item" v-for="(item,i) in floorList" :key=i>
        <!-- 标题 -->
        <view class="floor-title">
          <image :src="item.floor_title.image_src" mode=""></image>
        </view>
        <!-- 图片 -->
        <view class="floor-imgBox">
          <view class="left-img">
            <image :src="item.product_list[0].image_src" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}"></image>
          </view>
          <view class="right-img">
            <image :src="item1.image_src" mode="widthFix" v-for="(item1,i1) in item.product_list" :key='i1' v-if="i1!==0" :style="{width:item1.image_width+'rpx'}" @click="gotoGoods_list(item1)"></image>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        swiperList: [],
        navList:[],
        floorList:[]
      };
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods: {
      async getSwiperList() {
        const {data: res} = await uni.$http.get("/api/public/v1/home/swiperdata")
        if (res.meta.status !== 200) return uni.$message()
        this.swiperList = res.message
      },
      async getNavList() {
        const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
        if(res.meta.status!==200) return uni.$message()
        this.navList = res.message
      },
      async getFloorList() {
        const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
        if(res.meta.status!==200) return uni.$message()
        this.floorList = res.message
      },
      onNavClickHandle(item) {
        if(item.name === '分类'){
          uni.switchTab({
            url:'/pages/cate/cate'
          })
        }
      },
      gotoSearch() {
        uni.navigateTo({
          url:'/subpkg/search/search'
        })
      },
      gotoGoods_list(item) {
        uni.navigateTo({
          url:'/subpkg/goods_list/goods_list?' + item.navigator_url.split('?')[1]
        })
      }
    }
  }
</script>

<style lang="scss">
.swiperBox {
  height: 330rpx;
  .swiper-item{
    margin: 20rpx;
    image {
      width: 100%;
    }
  }
   
}

.nav-list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;
  .nav-item {
    image {
      width: 128rpx;
      height: 140rpx;
    }
  }
}

.floor-title image {
  height: 60rpx;
  width: 100%;
  display: flex;
}
.floor-imgBox {
  display: flex;
  .left-img {
    margin-left: 15rpx;
  }
  .right-img {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    image {
      width: 100%;
    }
  }
}
.search-box {
  position: sticky;
  top: 0;
  z-index: 999;
}
</style>
